import Mock from 'mockjs'
import { param2Obj } from '@/utils'

const List= []
const count = 30

for (let i = 0; i < count; i++) {
  List.push(Mock.mock({
    id:'@increment(1, 100)',
    comment: '@first',
    firstWithdraw:'@integer(1000, 10000)',
    'accountsCheck|1':[1,2],
    'ipsCheck|1':[1,2],
    totalWithdraw:'@integer(1, 10)',
    profit:'@integer(1000, 10000)',
    continuousWithdrawTimes:'@integer(1000, 10000)',
    continuousMinutes:'@integer(1000, 10000)',
    dailyWithdrawTimes:'@integer(1000, 10000)',
    singleWithdrawMax:'@integer(1000, 10000)',
    dailyWithdrawMax:'@integer(1000, 10000)',
    time: +Mock.Random.date('T'),
    'status|1': _.map(consts.STRATEGY_STATUS, 'value'),
  }))
}

export default {
  [api.STRATEGY_LIST]: config => {
    const { page = 1, limit = 20 } = param2Obj(config.body)

    let mockList = List.filter(item => {
      // if (importance && item.importance !== +importance) return false;
      if (status && Number(item.status) !== Number(status)) return false;
      // if (title && item.title.indexOf(title) < 0) return false;
      return true;
    })

    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1));

    return {
      data: {
        total: mockList.length,
        list: pageList
      },
      code: 1,
    };
  },
  [api.STRATEGY_DETAIL]: config => {
    const { id } = param2Obj(config.body)
    let detail = {}

    console.log('id',id,config)

    _.map(List,item=>{
      if(item.id == id){
        detail = item
      }
    })

    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    return {
      data: {
        detail:  detail
      },
      code: 1,
    };
  },
}
